﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QuickFramework.Orm
{
    /// <summary>
    /// 工作单元
    /// </summary>
    public interface IUnitOfWork : IDisposable, Shared.Contracts.IDependency
    {
        /// <summary>
        /// 创建数据库链接
        /// </summary>
        /// <param name="isMaster"></param>
        /// <returns></returns>
        IUnitOfWork CreateOpenConnection(string connectionStringName, bool isMaster = true);
        /// <summary>
        /// 工作单元链接
        /// </summary>
        public IDbConnection Connection
        {
            get;
        }
        /// <summary>
        /// 工作单元事务
        /// </summary>
        public IDbTransaction Transaction
        {
            get;
        }
        /// <summary>
        /// UnitOfWork ID
        /// </summary>
        public string ID
        {
            get;
        }
        /// <summary>
        /// 开启事务
        /// </summary>
        IUnitOfWork BeginTransaction();
        /// <summary>
        /// 开启事务
        /// </summary>
        IUnitOfWork BeginTransaction(IsolationLevel isolationLevel);
        /// <summary>
        /// 提交事务
        /// </summary>
         void Commit();
        /// <summary>
        /// 全局提交,无论嵌套多少事务,直接进行提交
        /// </summary>
        void CommitScope();
        /// <summary>
        /// 回滚事务
        /// </summary>
        void Rollback();
        /// <summary>
        /// 全局回滚,无论嵌套多少事务,直接进行回滚
        /// </summary>
        void RollbackScope();
        /// <summary>
        /// 销毁 / 关闭链接对象
        /// </summary>
        new void Dispose();
    }
}
